﻿define(function (require) {
    require('model/AppFuncList');
    var service = require('ezdesk/utility/service');

    $(function () {
        var AppSetListView = require('view/AppSetListView');
        var AppFuncListView = require('view/AppFuncListView');

        var appSetListView = new AppSetListView({ model: new AppFuncList });
        var appFuncListView = new AppFuncListView({ model: new AppFuncList });

        var allApps;
        service.AllAppFunctions_Cache(function (e) {
            allApps = e;
        });

        appSetListView.refreshAppFuncListCallback = function (categoryName) {
            appFuncListView.clear();
            
            var appfuncs = $.grep(allApps, function (item) {
                return item.Category.TypeName == categoryName;
            });

            appFuncListView.model.reset(appfuncs);
            appFuncListView.render();

        }

        service.AllAppFunctionCategories_Cache(function (allAppCategories) {
            appSetListView.model.reset(allAppCategories);
            appSetListView.render();
        });

    })
})
